import request from "@/utils/request";
import { ArticleType, CategoryType } from "@/types/course";
//新增课程分类
export const categoryPost = (cateObj: CategoryType) => {
  return request.post("/classes/ReactCategory", cateObj);
};

//分类列表
export const categoryGet = () => {
  return request.get("/classes/ReactCategory");
};

//分类状态更新
export const categoryPut = (objectId: string, status: boolean) => {
  return request.put(`/classes/ReactCategory/${objectId}`, { status });
};

//新增图文课程
export const articlePost = (artObj: ArticleType) => {
  return request.post("/classes/ReactAricle", artObj);
};

export interface IArticleParams {
  pageSize?: number | undefined;
  current?: number | undefined;
  keyword?: string | undefined;
  name: string;
  isvip: string;
}
//课程列表查询
export interface CourseConditionType {
  name?: Object;
  isvip?: boolean;
}
export const articleGet = (params: IArticleParams) => {
  let { name, isvip } = params;
  let condition: CourseConditionType = {
    name: { $regex: `${name ? name : ""}`, $options: "i" },
  };
  if (isvip) {
    condition.isvip = isvip == "true" ? true : false;
  }
  let cond = JSON.stringify(condition);
  return request.get(`/classes/ReactAricle?where=${cond}`);
};

//课程更新
export const articlePut = (objectId: string, artObj: ArticleType) => {
  return request.put(`/classes/ReactAricle/${objectId}`, artObj);
};

//按照分类统计课程数
export const chartGet = (catelv1: string) => {
  return request.get(
    `/classes/ReactAricle?where={"catelv1":"${catelv1}"}&count=1&limit=0`
  );
};
